const {
  Controller,
} = require('uni-cloud-router')
const ResponseUtil = require('../utils/Response')

module.exports = class RegisterController extends Controller {
  async register() {
    const {
      ctx,
      service,
    } = this
    const {
      avatarUrl,
      nickName,
      childName,
      code,
    } = ctx.event

    if (!avatarUrl || !nickName || !childName) {
      return ResponseUtil.error('参数错误')
    }

    return service.auth.register({
      ...ctx.event,
      avatarUrl: ctx.event.fileId,
    })
  }

  async login() {
    const {
      ctx,
      service,
    } = this

    return service.auth.login({
      ...ctx.event,
    })
  }
}
